const fs = require('fs');

var rds = fs.createReadStream('input.txt');
var cnt = 0;

var globalData = new Buffer('');

rds.on('data', function(trunk){
    cnt ++;
    console.log('第' + cnt + '次读取，共' + Buffer.byteLength(trunk) + '字节。');
    globalData += trunk;
    // console.log(trunk);
});

rds.on('end', function(){
    console.log("读取文件已完成！");
});

rds.on('close', function(){
    console.log('文件已关闭！')
    console.log(globalData);
});

rds.on('open', function(){
    console.log("文件已打开！");
});

rds.on('error', function(err){
    console.log(err);
});

console.log("程序执行完毕！");